public class Warenlager { public Liste bestand; public Warenlager() { bestand = new Liste( new Warenbestand( new Ware("Ayran", 1.99), 99) ); bestand.append( new Warenbestand( new Ware("Schokoriegel", 1.30), 70 ) ); bestand.append( new Warenbestand( new Ware("Stifte", .98), 53) ); bestand.append( new Warenbestand( new Ware("Briefmarken", .85), 490 ) ); bestand.append( new Warenbestand( new Ware("Kaugummis", 2.49), 30 ) ); bestand.append( new Warenbestand( new Ware("Gummibärchen", 3.00), 10 ) ); } public boolean existiert(int index) { return (bestand.get(index) != null); } public String toString() { String r = ""; Liste l; for (l = bestand; l != null; l = l. next) { r += l.data.toString() + "\n"; } r += String.format("%52.2f\n", wert()); return r; } public double wert() { Liste b; long r = 0; for (b = bestand; b != null; b = b.next) { r += ( ((Warenbestand) b.data).wert() * 100 ); } return ((double) r) / 100; } public Warenbestand get(int n) { Liste helper; helper = bestand.get(n); // return (Warenbestand) bestand.get(n).data; if ( helper == null ) { return null; } else { return (Warenbestand) helper.data; } } public static boolean test() { // Warenbestand.main(new String[0]); assert(Warenbestand.test()); System.out.print("Warenlager: "); Warenlager testlager = new Warenlager(); assert( testlager.wert() == 861.15); assert( testlager.existiert(0)); assert( testlager.existiert(5)); assert( ! testlager.existiert(6)); assert( ! testlager.existiert(-1)); assert( testlager.get(0).toString().equals( ( new Warenbestand(new Ware("Ayran", 1.99), 99) ).toString() )); assert( testlager.get(5).toString().equals( ( new Warenbestand(new Ware("Gummibärchen", 3.0), 10) ).toString() )); assert( testlager.get(6) == null ); assert( testlager.get(-1) == null ); System.out.println("passed"); return true; } public static void main(String[] args) { test(); } }